package com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.entity.TongJiInfo;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.ICaseSelectionManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * @author py
 * @Date
 */
@Controller
@RequestMapping("/caseSelectionManagement")
public class CaseSelectionManagementController extends BaseController {
    @Autowired
    ICaseSelectionManagementService service;

    private String PREFIX = "/remoteSynergy/";
    
    /**
     * 跳转到病例分配管理页面
     */
    @RequestMapping("")
    public String to_caseSelection(Model model) {
        String tableHead = ShiroKit.getSessionAttr("abbreviation");
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "/case_selection_management.html";
    }

    /**
     * 病例上传管理列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object getInfoList(SearchCaseSelectionManagementInfo info, HttpServletRequest request) {
        Page<CaseSelectionManagementInfo> page = new PageFactory<CaseSelectionManagementInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<CaseSelectionManagementInfo> list = service.selectPageListByQueryGetMap(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.selectPageListByQueryGetMap(page, info);
            }
            page.setTotal(service.getQueryPagesCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 病例评分统计数量
     */
    @RequestMapping("/caseSelectionManagementTotal")
    @ResponseBody
    public List<TongJiInfo> caseSelectionManagementTotal(SearchCaseSelectionManagementInfo searchInfo, HttpServletRequest request) {
        return service.caseSelectionManagementTotal(searchInfo);
    }
}